package com.itheima.web.servlet;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpSession;
import java.io.IOException;

@WebServlet("/sesDemo1")
public class SessionDemo1 extends HttpServlet {
    @Override
    protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
        System.out.println("SessionDemo1...");
        // 获取Session,如果不存在，就让容器构建一个session
        HttpSession httpSession = req.getSession();
        System.out.println("id:"+httpSession.getId());
        // 往session存东西
        httpSession.setAttribute("userId","1001");
        httpSession.setAttribute("username","zhangsan");
        System.out.println("往session存数据");

    }
}
